<?php

define('REP_ROOT', '');
require(REP_ROOT . 'config.php');
$format = Annuaire::lookup(KEY_FORMAT);

if(!isset($_SESSION['id_user']))
    redirectFront('connexion');

if(!isset($_GET['id']))
    redirectFront('profil');

$id_discussion = $_GET['id'];
modelReportingDiscussion::markAsRead($id_discussion);
$_SESSION['new_message'] = modelUser::hasNewMessage($_SESSION['id_user']);


$page = new rootLayoutPage();
$discussion = modelReportingDiscussion::getDiscussionNew($id_discussion);


///test access right

if($discussion->id_user!=$_SESSION['id_user']){
	redirectFront('index');
}

$page->setBaliseTitle($discussion->titre);
$page->setDescription('profil_message_lire_description');

//-- menu Left show products--------------------------------//
$menu = new layoutMenuLeft();
$menuCategorie = new layoutMenuPage();
$menu->pushMenu($menuCategorie);
$menuPage = new layoutMenuPage();
$menu->pushMenu($menuPage);
$page->setMenuPage($menu);

//-- corps de la page ----------//
$tpl_file='profil-message-lire.tpl';
$profil_message_lire = new flyLayout(REP_TPL . $tpl_file);
$profil_message_lire->start();
$translate = tmxTranslate('profil-message.xml', REP_XLAT_TEMPLATE);
$language_folder = $_SESSION['language_code']==language_default?'':'/'.$_SESSION['language_code'];
$profil_message_lire->setVariable('language_folder', $language_folder);
/*$tabs = new layoutTabs();
$tabs->pushLink('Mon compte', '/profil.php');
$tabs->pushLink('Mes messages', '/profil-message.php');
$profil_message_lire->includeLayout('tabs', $tabs);*/

$profil_message_lire->setVariable('titre', $discussion->titre);

if($discussion->id_prev) {
    $profil_message_lire->setVariable('url_precedent','/profil-message-lire.php?id='.$discussion->id_prev);
    $profil_message_lire->showBlock('precedent');
}
if($discussion->id_next) {
    $profil_message_lire->setVariable('url_suivant','/profil-message-lire.php?id='.$discussion->id_next);
    $profil_message_lire->showBlock('suivant');
}

$listMessage = modelReportingDiscussion::getListMessage($id_discussion);
foreach($listMessage as $key => $message) {
    $profil_message_lire->setVariable('auteur', $message->login);
	$profil_message_lire->setVariable('date', affiche($message->date_creation,'dateheure'));
    $profil_message_lire->setVariable('message', nl2br($message->message));
    $profil_message_lire->parseList('list_message');
}
$profil_message_lire->setVariable('id_discussion', $id_discussion);

$profil_message_lire->stop();


$page->setBody($profil_message_lire);
$page->display();

?>